package com.zkingsoft.actions.admin;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zkingsoft.actions.common.BaseController;
import com.zkingsoft.anotations.RemoveRequestToken;
import com.zkingsoft.anotations.SaveRequestToken;
import com.zkingsoft.constance.Dictionary;
import com.zkingsoft.model.SendReport;
import com.zkingsoft.plugin.pojo.PaginationVO;
import com.zkingsoft.plugin.util.WebUtil;
import com.zkingsoft.pojo.AjaxResult;
import com.zkingsoft.services.ProjectService;
import com.zkingsoft.services.SendReportService;

/**
 * This field was generated by Zking.software.Codegen.
 * @date 2016-11-11 10:23
 */
@Controller
@RequestMapping(value = "admin/sendReport")
public class SendReportController extends BaseController{

	@Resource
	private SendReportService currentService;
	@Resource
	private ProjectService projectService;
	
	/**
	 * 列表显示
	 */
	@RequestMapping(value = "/showList")
	public @ResponseBody AjaxResult showList(SendReport sendReport, PaginationVO pageVo) {
		sendReport.setReceiveId(getMe().getId());
		return showList(currentService, sendReport, pageVo);
	}
	/**
	 *进入页面
	 */
	@RequestMapping(value = "/sendReport")
	public String all(Long id) {
		if(id != null){
			WebUtil.getRequest().setAttribute("obj", projectService.findById(id));
		}
		return "admin/sendReport-list";
	}
   	
	/**
	 * 新增或者修改页面
	 */   
	@RemoveRequestToken	
   	@RequestMapping(value = "/addOrModify")
	public @ResponseBody AjaxResult addOrModify(SendReport sendReport) {
		if (sendReport.getId() != null) {
			return modify(currentService, sendReport, "sendReport");
		} else {
			return add(currentService, sendReport, "sendReport");
		}
	}
	
	/**
	 * 附件路径查询
	 */   
 	@RequestMapping(value = "/queryFileUrl")
	public @ResponseBody AjaxResult queryFileUrl(long id) {
 		SendReport sendReport = currentService.findById(id);
 		if(sendReport != null){
 			if(sendReport.getReport().getFileUrl() != null && sendReport.getReport().getFileUrl() !=""){
 				return new AjaxResult(AjaxResult.STATUS_OK, null,sendReport.getReport().getFileUrl());
 			}else{
 				return new AjaxResult(AjaxResult.STATUS_ERR, null,null);
 			}
 		}else {
 			return new AjaxResult(AjaxResult.STATUS_ERR, null,null);
 		}
 	}
	
   	/**
	 * 进入修改界面
	 */   
	@SaveRequestToken
   	@RequestMapping(value = "/editForm")
	public String editForm(Long id) {
		SendReport sendReport;
		if (id != null) {
			sendReport = currentService.findById(id);
			WebUtil.getRequest().setAttribute("obj", sendReport);
		}
		return "admin/sendReport-form";
	}
   	
   	
   	/**
	 * 删除
	 */  
 	@RequestMapping(value = "/del")
	public @ResponseBody AjaxResult del(String keys) {
		return remove(currentService, keys);
	}
 	

   	/**
	 * 修改
	 */  
 	@RequestMapping(value = "/update")
	public @ResponseBody AjaxResult update(SendReport sendReport) {
 		sendReport.setStatus(Dictionary.SENDREPORT_STATUS_YYD);
 		currentService.modify(sendReport);
		return new AjaxResult(AjaxResult.STATUS_OK, null,null);
 	}
  
}